<template>
  <a-modal
    title="操作"
    style="top: 20px;"
    :width="600"
    v-model="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
  >
    <a-form :form="form">
      <a-form-item style="display:none">
        <a-input v-decorator="['id']" />
      </a-form-item>
      <a-form-item
        :labelCol="labelCol"
        :wrapperCol="wrapperCol"
        label="方案名称"
      >
        <a-input
          placeholder="请输入"
          v-decorator="['schemeName', {rules: [{ required: true, message: '请输入方案名称' }]}]"
        />
      </a-form-item>

      <a-form-item
        :labelCol="labelCol"
        :wrapperCol="wrapperCol"
        label="高端品牌   保费"
      >
        <!-- <span class="premiumLabel">保费：</span> -->
        <a-input
          class="input"
          placeholder="请输入"
          v-decorator="['highInsurancePremium', {rules: [{ required: true, message: '请输入保费' }]}]"
        />
        <!-- <span class="highCompensationNum">最大赔偿次数：</span>
        <a-input
          class="input"
          placeholder="请输入"
          v-decorator="['highCompensationNum', {rules: [{ required: true, message: '请输入最大赔偿次数' }]}]"
        /> -->
      </a-form-item>

      <a-form-item
        :labelCol="labelCol"
        :wrapperCol="wrapperCol"
        label="中端品牌   保费"
      >
        <!-- <span class="premiumLabel">保费：</span> -->
        <a-input
          class="input"
          placeholder="请输入"
          v-decorator="['middleInsurancePremium', {rules: [{ required: true, message: '请输入保费' }]}]"
        />
        <!-- <span class="highCompensationNum">最大赔偿次数：</span>
        <a-input
          class="input"
          placeholder="请输入"
          v-decorator="['inCompensationNum', {rules: [{ required: true, message: '请输入最大赔偿次数' }]}]"
        /> -->
      </a-form-item>
      <a-form-item
        :labelCol="labelCol"
        :wrapperCol="wrapperCol"
        label="低端品牌   保费"
      >
        <!-- <span class="premiumLabel">保费：</span> -->
        <a-input
          class="input"
          placeholder="请输入"
          v-decorator="['lowInsurancePremium', {rules: [{ required: true, message: '请输入保费' }]}]"
        />
        <!-- <span class="highCompensationNum">最大赔偿次数：</span> -->
        <!-- <a-input
          class="input"
          placeholder="请输入"
          v-decorator="['lowCompensationNum', {rules: [{ required: true, message: '请输入最大赔偿次数' }]}]"
        /> -->
      </a-form-item>
      <a-form-item
        :labelCol="labelCol"
        :wrapperCol="wrapperCol"
        label="最大赔偿次数"
      >
        <!-- <span class="premiumLabel">保费：</span> -->
        <!-- <a-input
          class="input"
          placeholder="请输入"
          v-decorator="['lowPremium', {rules: [{ required: true, message: '请输入保费' }]}]"
        /> -->
        <!-- <span class="highCompensationNum">最大赔偿次数：</span> -->
        <a-input
          class="input"
          placeholder="请输入"
          v-decorator="['maxPeichangNum', {rules: [{ required: true, message: '请输入最大赔偿次数' }]}]"
        />
      </a-form-item>

    </a-form>
  </a-modal>
</template>
<script>
import { saveSysInsuranceSchemeConfig } from '@/api/system'
import pick from 'lodash.pick'
export default {
  name: 'Modal',
  props: {
    deeps: {
      type: Array,
      required: true
    }
  },
  components: {
  },
  data () {
    return {
      visible: false,
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      confirmLoading: false,
      mdl: {},
      options: [],
      city: [],
      form: this.$form.createForm(this)
    }
  },
  beforeCreate () {
  },
  created () {
  },
  methods: {
    add () {
      this.form.resetFields()
      this.edit({ dictId: 0 })
    },
    edit (record) {
      this.mdl = Object.assign(record)
      this.visible = true
      this.$nextTick(() => {
        this.form.setFieldsValue(pick(this.mdl, 'schemeName', 'highInsurancePremium', 'id', 'lowInsurancePremium', 'maxPeichangNum', 'middleInsurancePremium'))
      })
    },
    handleSubmit (e) {
      e.preventDefault()
      this.form.validateFields((err, values) => {
        if (!err) {
          console.log('Received values of form: ', values)
          this.confirmLoading = true
          saveSysInsuranceSchemeConfig(values).then(res => {
            if (res.code === 0) {
              this.$message.success('保存成功')
              this.$emit('ok')
              this.visible = false
            } else {
              this.$message.success(res.msg)
            }
          }).catch(() => {
            this.$message.error('系统错误，请稍后再试')
          }).finally(() => {
            this.confirmLoading = false
          })
        }
      })
    }
  },
  watch: {
    /*
      'selectedRows': function (selectedRows) {
        this.needTotalList = this.needTotalList.map(item => {
          return {
            ...item,
            total: selectedRows.reduce( (sum, val) => {
              return sum + val[item.dataIndex]
            }, 0)
          }
        })
      }
      */
  }
}
</script>
<style scorp>
  .ant-modal-body .ant-row{
    height: 16px;
  }
  .ant-modal-body{
    padding: 35px;
  }
</style>
